package com.cmict.data.form.api.util.SubUtil;

import com.cmict.data.framework.common.pojo.CommonResult;
import com.cmict.data.form.api.entity.dataobject.SysFormDO;
import com.cmict.data.form.api.service.SysCurrencyService;
import com.cmict.data.system.api.dict.DictDataApi;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import static com.cmict.data.framework.common.pojo.CommonResult.success;

/**
 * @description: 组件分配
 * @author: qiaoyu
 * @create: 2022-07-6 22:57
 **/
public class ElDistrUtil {

	public static CommonResult distr (SysFormDO sysFormDO , String value, int k, DictDataApi dictDataService, SysCurrencyService sysCurrencyService) {
		JSONObject personData = JSON.parseObject(sysFormDO.getFormJsonUser());
		JSONArray fields = personData.getJSONArray("fields");
		JSONObject field = fields.getJSONObject(k);
		JSONObject config = field.getJSONObject("__config__");
		String tag = config.getString("tag");
		if(tag.equals("el-input")){
			String tagIcon = config.getString("tagIcon");
			//单文本
			if(tagIcon.equals("input")){
				return ElInputUtil.rule(personData,value,k);
			}
			//多文本
			if(tagIcon.equals("textarea")){
				return ElTextareaUtil.rule(personData,value,k);
			}
			//密码
			if(tagIcon.equals("password")){
				return ElPasswordUtil.rule(personData,value,k);
			}
			//编码
			if(tagIcon.equals("coding")){
				return ElCodeUtil.rule(personData,value,k);
			}
		}
		//计数器
		if(tag.equals("el-input-number")){
			String tagIcon = config.getString("tagIcon");
			if(tagIcon.equals("number")){
				return ElNumberUtil.rule(personData,value,k);
			}
		}
		//富文本
		if(tag.equals("tinymce")){
			String tagIcon = config.getString("tagIcon");
			if(tagIcon.equals("rich-text")){
				return ElTextUtil.rule(personData,value,k);
			}
		}
		//手写签名
		if(tag.equals("signature")){
			String tagIcon = config.getString("tagIcon");
			if(tagIcon.equals("email")){
				return ElTextUtil.rule(personData,value,k);
			}
		}
		//下拉框
		if(tag.equals("my-select")){
			String tagIcon = config.getString("tagIcon");
			if(tagIcon.equals("select")){
				return ElSelectUtil.rule(personData,value,k,dictDataService,sysCurrencyService);
			}
		}
		//级联选择
		if(tag.equals("my-cascader")){
			String tagIcon = config.getString("tagIcon");
			if(tagIcon.equals("cascader")){
				return ElCascaderUtil.rule(personData,value,k);
			}
		}
		//单选框组
		if(tag.equals("my-radio-group")){
			String tagIcon = config.getString("tagIcon");
			if(tagIcon.equals("radio")){
				return ElSelectUtil.rule(personData,value,k,dictDataService,sysCurrencyService);
			}
		}
		//多选框组
		if(tag.equals("my-checkbox-group")){
			String tagIcon = config.getString("tagIcon");
			if(tagIcon.equals("checkbox")){
				return ElSelectUtil.rule(personData,value,k,dictDataService,sysCurrencyService);
			}
		}
		//开关
		if(tag.equals("el-switch")){
			String tagIcon = config.getString("tagIcon");
			if(tagIcon.equals("switch")){
				return ElSelectUtil.rule(personData,value,k,dictDataService,sysCurrencyService);
			}
		}
		//滑块
		if(tag.equals("el-slider")){
			String tagIcon = config.getString("tagIcon");
			if(tagIcon.equals("slider")){
				return ElSelectUtil.rule(personData,value,k,dictDataService,sysCurrencyService);
			}
		}
		//时间选择
		if(tag.equals("el-time-picker")){
			String tagIcon = config.getString("tagIcon");
			if(tagIcon.equals("time")){
				return ElTimeUtil.rule(personData,value,k);
			}
			//时间范围
			if(tagIcon.equals("time-range")){
				return ElTimeRangeUtil.rule(personData,value,k);
			}
		}
		//日期选择
		if(tag.equals("el-date-picker")){
			String tagIcon = config.getString("tagIcon");
			if(tagIcon.equals("date")){
				return ElDateUtil.rule(personData,value,k);
			}
			//日期范围
			if(tagIcon.equals("date-range")){
				return ElDateRangeUtil.rule(personData,value,k);
			}
		}
		//评分
		if(tag.equals("el-rate")){
			String tagIcon = config.getString("tagIcon");
			if(tagIcon.equals("rate")){
				return ElRateUtil.rule(personData,value,k);
			}
		}
		//颜色
		if(tag.equals("el-color-picker")){
			String tagIcon = config.getString("tagIcon");
			if(tagIcon.equals("color")){
				return ElColorUtil.rule(personData,value,k);
			}
		}
		//地点
		if(tag.equals("getMapPoint")){
			String tagIcon = config.getString("tagIcon");
			if(tagIcon.equals("place")){
				return ElPlaceUtil.rule(personData,value,k);
			}
		}
		//行政区域
		if(tag.equals("my-region")){
			String tagIcon = config.getString("tagIcon");
			if(tagIcon.equals("tree-table")){
				return ElTableUtil.rule(personData,value,k);
			}
		}
		//行政区域
		if(tag.equals("my-region")){
			String tagIcon = config.getString("tagIcon");
			if(tagIcon.equals("tree-table")){
				return ElTableUtil.rule(personData,value,k);
			}
		}
		//联想弹窗
		if(tag.equals("LenovoPopup")){
			String tagIcon = config.getString("tagIcon");
			if(tagIcon.equals("lenovoPopup")){
				return ElLenovoUtil.rule(personData,value,k);
			}
		}
		return success( "通过",true);
	}
}

